Imports TaxonNamesInterface

Public Class SelectMergeNameForm

    Public Names As DataSet
    Public SelectedNameGuid As Guid

    Private Sub SelectMergeNameForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Names Is Nothing Then
            DataGridView1.DataSource = Names
            DataGridView1.DataMember = Names.Tables(0).TableName
        End If
    End Sub

    Private Sub NewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim n As New Name

            'parent
            Dim selForm As New SelectNameForm
            selForm.Title = "Select parent name for the new name"
            If selForm.ShowDialog = Windows.Forms.DialogResult.OK Then
                n.ParentNameId = selForm.SelectedName.NameId
                n.ParentName = selForm.SelectedName
            End If

            'rank
            Dim rnkForm As New SelectRankForm
            If rnkForm.ShowDialog = Windows.Forms.DialogResult.OK Then
                n.RankId = rnkForm.SelectedRank.RankId
            End If

            'canonical
            Dim grab As New GrabTextForm
            grab.Title = "Enter canonical for new name"
            If grab.ShowDialog = Windows.Forms.DialogResult.OK Then
                n.Canonical = grab.EnteredText
            End If

            NamesClient.NamesInterfaceProxy.InsertUpdateName(n, SessionState.CurrentUser.Login)

            SelectedNameGuid = n.NameId
            DialogResult = Windows.Forms.DialogResult.OK

        Catch ex As Exception
            NamesClient.NamesInterfaceProxy = Nothing
        End Try
    End Sub

    Private Sub SelectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectButton.Click
        If DataGridView1.SelectedRows.Count > 0 Then
            SelectedNameGuid = DataGridView1.CurrentRow.Cells("NameId").Value
            DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub CncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CncButton.Click
        DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
End Class